<template>
  <div>
    <product :img-src="products"></product>
  </div>
</template>

<script>
import product from "../components/product";

export default {
  name: "Products",
  data() {
    return {
      product: {
        id: "",
        name: "",
        stock: "",
        cid: "",
        pdesc: "",
        img: null,
        category: {
          name: ""
        }
      },
      products: null
    };
  },
  watch: {
    $route: function() {
      this.getProducts();
    }
  },
  created() {
    console.log(1);
    this.getProducts();
  },
  methods: {
    scroll() {
      var scrollTop =
        window.pageYOffset ||
        document.documentElement.scrollTop ||
        document.body.scrollTop;
      this.top = scrollTop;
    },
    getProducts() {
      let params = {
        pdesc: this.$route.query.name == null ? "" : this.$route.query.name,
        cid: this.$route.query.cid
      };
      this.$myPost(
        this,
        "/product/public/queryByDescAndCid",
        (res) => {
          this.products = res.data.data;
        },
        params
      );
    }
  },
  components: {
    product: product
  }
};
</script>

<style scoped>
</style>